package com.itheima.HomeWork;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo03 {
    public static void main(String[] args) {
        HashMap<Integer, String> peoples = new HashMap<>();
        peoples.put(1,"张三");
        peoples.put(2,"李四");
        peoples.put(3,"王五");
        //打印集合大小
        System.out.println(peoples.size());
        //用键找值的方式遍历集合
        Set<Integer> keys = peoples.keySet();
        for(Integer key:keys){
            System.out.println(key+":"+peoples.get(key));
        }
        //用键值对的方式遍历
        Set<Map.Entry<Integer, String>> entries = peoples.entrySet();
        for(Map.Entry<Integer,String> entry:entries){
            System.out.println(entry.getValue()+":"+entry.getValue());
        }
        //获取键位1的值
        System.out.println(peoples.get(1));
        //获取键为10的值
        System.out.println(peoples.get(10));
        //判断集合是否有键
        System.out.println(peoples.containsKey(10));
        //删除键为1的键值对 打印
        peoples.remove(1);
        System.out.println(peoples);
    }
}
